Managing MIDI Thru

You can connect a MIDI input device directly to a MIDI output device so that when the input device receives an MIM_DATA1NQKYYP message, the system sends a message with the same MIDI event data to the output device driver. To connect a MIDI output device to a MIDI input device, use the midiConnect1Y7JZIL function.

To achieve the best possible performance with multiple outputs, an application can choose to supply a special form of MIDI output driver, called a thru driver. Although the system allows only one MIDI output device to be connected to a MIDI input device, multiple MIDI output devices can be connected to a thru driver. An application on such a system could connect the MIDI input device to this thru device and connect the MIDI thru device to as many MIDI output devices as needed. For more information about thru drivers, see the Windows device-driver documentation.

Using Messages to Manage MIDI Recording

The following messages can be sent to a window or thread callback procedure for managing MIDI recording:

MM_MIM_CLOSE5G.I25

Sent when a MIDI input device is closed by using the midiInClose37AK_6N function.

MM_MIM_DATARQ_M7

Sent when a complete MIDI message is received. (This message is used for all MIDI messages except system-exclusive messages.)

MM_MIM_ERROR5IBKYB

Sent when an invalid MIDI message is received. (This message is used for all MIDI messages except system-exclusive messages.)

MM_MIM_LONGDATAKTAI_L

Sent when either a complete MIDI system-exclusive message is received or when a buffer has been filled with system-exclusive data.

MM_MIM_LONGERRORLRSN0W

Sent when an invalid MIDI system-exclusive message is received.

MM_MIM_MOREDATA1JB50JI

Sent when an application is not processing MIM_DATA1NQKYYP messages fast enough to keep up with the input device driver.

MM_MIM_OPENN1_KUT

Sent when a MIDI input device is opened by using the midiInOpenFUXRPR function.

 

A wParam parameter and an lParam parameter are associated with each of these messages. The wParam parameter always specifies the handle of an open MIDI device. The lParam parameter is unused for the MM_MIM_CLOSE5G.I25 and MM_MIM_OPENN1_KUT messages.

For the MM_MIM_LONGDATAKTAI_L message, lpMidiHdr specifies an address of a MIDIHDR8OW3.JO structure that identifies the buffer for system-exclusive messages. The buffer may not be completely filled, because the size of the system-exclusive messages is usually not known before being recorded and because buffers whose total size can contain the largest expected message must be allocated. To determine the amount of valid data present in the buffer, use the dwBytesRecorded member of the MIDIHDR structure.

Using a Callback Function to Manage MIDI Recording

You can define your own callback function to manage recording for MIDI input devices. The callback function is documented as MidiInProcFUYTZG.

The following messages can be sent to the wMsg parameter of the MidiInProc callback function:

MIM_CLOSE1PPLZH2

Sent when the device is closed by using the midiInClose37AK_6N function.

 

MIM_DATA1NQKYYP

Sent when a complete MIDI message is received (this message is used for all MIDI messages except system-exclusive messages).

 

MIM_ERROR13IG2WZ

Sent when an invalid MIDI message is received (this message is used for all MIDI messages except system-exclusive messages).

 

 

MIM_LONGDATACN33SA

Sent when either a complete MIDI system-exclusive message is received or when a buffer has been filled with system-exclusive data.

MIM_LONGERROR21E02J5

Sent when an invalid MIDI system-exclusive message is received.

 

MIM_MOREDATA2T9Q1I

Sent when an application is not processing MIM_DATA1NQKYYP messages fast enough to keep up with the input device driver.

 

MIM_OPEN1NQW_K2

Sent when the MIDI input device is opened by using the midiInOpenFUXRPR function.

 

 

These messages are similar to those sent to window procedure functions, but the parameters are different. A handle of the open MIDI device is passed as a parameter to the callback function, along with the doubleword of instance data that was passed by using midiInOpen.

For the MIM_LONGDATACN33SA message, lpMidiHdr specifies an address of a MIDIHDR8OW3.JO structure that identifies the buffer for system-exclusive messages. The buffer might not be completely filled. To determine the amount of valid data present in the buffer, use the dwBytesRecorded member of the MIDIHDR structure.

After the device driver is finished with a data block, you can clean up and free the data block.